package net.wofly.right.validator;


import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import net.wofly.common.util.GeneralHelper;
import net.wofly.right.domain.Organization;
import net.wofly.right.domain.ReceivingAddr;
import net.wofly.right.domain.User;
import net.wofly.right.dto.CustomDto;

public class UserValidator {
    
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");
    
    public static String validateUserID(String userID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("员工ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateOrderType(String orderType) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(orderType)) {
            stringBuffer.append("订单类型不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static void validateUserID(StringBuffer stringBuffer, String userID) {
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }
    }
    
    public static void validateUserName(StringBuffer stringBuffer, String userName) {
        if (StringUtils.isEmpty(userName)) {
            stringBuffer.append("用户userName不能为空！").append(lineSeparator);
        }
    }
    
    public static String validateFinishRegisterByMobileParams(String mobile, String password, String verifyCode) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (StringUtils.isEmpty(mobile)) {
            stringBuffer.append("客户（会员）手机号码(mobile)不能为空！").append(lineSeparator);
        }
        if (StringUtils.isEmpty(password)) {
            stringBuffer.append("客户（会员）密码(password)不能为空！").append(lineSeparator);
        }
        if (StringUtils.isEmpty(verifyCode)) {
            stringBuffer.append("客户（会员）验证码(verifyCode)不能为空！").append(lineSeparator);
        }
        
        return stringBuffer.toString();
    }
    
    public static String validateAddUserParams(User user) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (user == null) {
            stringBuffer.append("客户实体不能为空！").append(lineSeparator);
        } else {
            stringBuffer.append(validateUserID(user.getUserID()));
            if (StringUtils.isEmpty(user.getName())) {
                stringBuffer.append("客户姓名(name)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getMobile())) {
                stringBuffer.append("客户（会员）手机号码(mobile)不能为空！").append(lineSeparator);
            } else if (!GeneralHelper.isMobile(user.getMobile())) {
                stringBuffer.append("客户（会员）手机号码(mobile)格式不正确！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getPassword())) {
                stringBuffer.append("客户（会员）密码(password)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRegisterWay())) {
                stringBuffer.append("客户性别不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getAgencyUserID())) {
                stringBuffer.append("代理注册人(agencyUserID)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRegisterWay())) {
                stringBuffer.append("客户注册类型不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRoleID())) {
                stringBuffer.append("客户角色不能为空！").append(lineSeparator);
            }
            if (null == user.getIsLegal()) {
                stringBuffer.append("是否法人不能为空！").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateCheckUserParams(User user,String userID) {
        StringBuffer stringBuffer = new StringBuffer();
    
        if (user == null) {
            stringBuffer.append("客户实体不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(user.getName())) {
                stringBuffer.append("客户姓名(name)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getMobile())) {
                stringBuffer.append("客户（会员）手机号码(mobile)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getPassword())) {
                stringBuffer.append("客户（会员）密码(password)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRegisterWay())) {
                stringBuffer.append("客户性别不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getAgencyUserID())) {
                stringBuffer.append("代理注册人(agencyUserID)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRegisterWay())) {
                stringBuffer.append("客户类型不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getStatus())) {
                stringBuffer.append("客户状态不能为空！").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateLoginParams(String accountID, String password) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (StringUtils.isEmpty(accountID)) {
            stringBuffer.append("客户（会员）账号(accountID)不能为空！").append(lineSeparator);
        }
        if (StringUtils.isEmpty(password)) {
            stringBuffer.append("客户（会员）密码(password)不能为空！").append(lineSeparator);
        }
        
        return stringBuffer.toString();
    }
    
    
    public static String validateSendMobileVerifyCode(String mobile) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (StringUtils.isEmpty(mobile)) {
            stringBuffer.append("客户（会员）手机号码(mobile)不能为空！").append(lineSeparator);
        }
        if (!GeneralHelper.isMobile(mobile)) {
            stringBuffer.append("客户（会员）手机号码(mobile)格式不正确！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateAddReceivingAddrParams(ReceivingAddr receivingAddr) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == receivingAddr) {
            stringBuffer.append("客户收货地址实体不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(receivingAddr.getContacts())) {
                stringBuffer.append("收货地址联系人不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(receivingAddr.getMobile())) {
                stringBuffer.append("收货人电话不能为空！").append(lineSeparator);
            }
           /* if (GeneralHelper.isMobile(receivingAddr.getMobile())) {
                stringBuffer.append("收货人电话格式不正确！").append(lineSeparator);
            }*/
            if (StringUtils.isEmpty(receivingAddr.getReceivingAddr())) {
                stringBuffer.append("收货人收货地址不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(receivingAddr.getOptUserID())) {
                stringBuffer.append("操作人不能为空！").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }
    
    public static String validateUpdateReceivingAddrParams(ReceivingAddr receivingAddr) {
        String errorMsg = validateAddReceivingAddrParams(receivingAddr);
        StringBuffer stringBuffer = new StringBuffer(errorMsg);
        if (null == receivingAddr) {
            stringBuffer.append("客户收货地址实体不能为空！").append(lineSeparator);
        } else {
            stringBuffer.append(validateReceivingAddrID(receivingAddr.getReceivingAddrID()));
        }
        return stringBuffer.toString();
    }
    
    public static String validateSetDefaultReceivingAddrParams(String receivingAddrID ,Integer defaultFlag) {
        StringBuffer stringBuffer = new StringBuffer();
        if (null == receivingAddrID) {
            stringBuffer.append("客户收货地址ID不能为空！").append(lineSeparator);
        }
        
        if (null == defaultFlag) {
            stringBuffer.append("客户收货地址是否默认标志不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }
    
    
    public static String validateReceivingAddrID(String receivingAddrID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(receivingAddrID)) {
            stringBuffer.append("收货地址ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
    
    public static String validateSetUserFollowParams(String userID, String customerUserID) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(validateUserID(userID)).append(validateUserID(customerUserID));
        return stringBuffer.toString();
    }
    
    public static String validateGetUserForOrder(String userID, String orderType) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(validateUserID(userID)).append(validateOrderType(orderType));
        return stringBuffer.toString();
    }
    
    
    public static String validateAddCustomParams(Organization organization) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (null == organization) {
            stringBuffer.append("客户实体不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(organization.getOrganizationName())) {
                stringBuffer.append("客户机构名称不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getMobile())) {
                stringBuffer.append("联系人手机号不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getLinkman())) {
                stringBuffer.append("联系人不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(organization.getOrganizationType())) {
                stringBuffer.append("客户类型不能为空！").append(lineSeparator);
            }
        }
        
        return stringBuffer.toString();
    }
    
    public static String validateSaveCustomParams(CustomDto customDto) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (null == customDto) {
            stringBuffer.append("客户实体不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(customDto.getCustomName())) {
                stringBuffer.append("客户名称不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(customDto.getMobile())) {
                stringBuffer.append("联系人手机号不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(customDto.getLinkman())) {
                stringBuffer.append("联系人不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(customDto.getOrganizationType())) {
                stringBuffer.append("客户类型不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(customDto.getFollowUserID())) {
                stringBuffer.append("客户维护人不能为空！").append(lineSeparator);
            }
        }
        
        return stringBuffer.toString();
    }
    
    public static String validateGetCustomParams(String userID) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("客户ID不能为空！").append(lineSeparator);
        } 
        return stringBuffer.toString();
    }
    
    public static String validateAddPersonalCustomParams(User user) {
        StringBuffer stringBuffer = new StringBuffer();
        
        if (user == null) {
            stringBuffer.append("客户实体不能为空！").append(lineSeparator);
        } else {
            if (StringUtils.isEmpty(user.getName())) {
                stringBuffer.append("客户姓名(name)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getMobile())) {
                stringBuffer.append("客户（会员）手机号码(mobile)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getAddr())) {
                stringBuffer.append("客户（会员）送货地址不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getPassword())) {
                stringBuffer.append("客户（会员）密码(password)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRegisterWay())) {
                stringBuffer.append("客户性别不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getAgencyUserID())) {
                stringBuffer.append("代理注册人(agencyUserID)不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getRegisterWay())) {
                stringBuffer.append("客户类型不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(user.getStatus())) {
                stringBuffer.append("客户状态不能为空！").append(lineSeparator);
            }
        }
        return stringBuffer.toString();
    }

    public static String validateChangeMobileParams(String userID, String pwd, String newMobile, String verifyCode) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }

        if (StringUtils.isEmpty(pwd)) {
            stringBuffer.append("密码不能为空！").append(lineSeparator);
        }

        if (StringUtils.isEmpty(newMobile)) {
            stringBuffer.append("新手机号不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateFindPwdByMobileParams(String mobile, String verifyCode, String newPwd) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(mobile)) {
            stringBuffer.append("手机号不能为空！").append(lineSeparator);
        }

        if (StringUtils.isEmpty(verifyCode)) {
            stringBuffer.append("验证码不能为空！").append(lineSeparator);
        }

        if (StringUtils.isEmpty(newPwd)) {
            stringBuffer.append("新密码不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateGetUserParams(String userID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }


    public static String validateModifyPwdParams(String userID, String oldPwd, String newPwd) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }

        if (StringUtils.isEmpty(oldPwd)) {
            stringBuffer.append("旧密码不能为空！").append(lineSeparator);
        }

        if (StringUtils.isEmpty(newPwd)) {
            stringBuffer.append("新密码不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateSetUserNickNameParams(String userID, String nickName, Integer sex) {

        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }

    public static String validateUploadUserHeadPicParams(String userID, MultipartFile headPic) {

        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }

        if (headPic == null) {
            stringBuffer.append("头像不能为空！").append(lineSeparator);
        }

        return stringBuffer.toString();
    }
    
}
